package com.sq.partner.manager.util;

import java.math.BigDecimal;

public class DecimalUtil {
	
	private static final BigDecimal D1 = BigDecimal.ONE;
	
	public static String toString(BigDecimal val,int scale){
		if(val == null){
			val = BigDecimal.ZERO;
		}
		
		return val.divide(D1, scale, BigDecimal.ROUND_HALF_UP).toString();
	}
	
	public static double toDouble(BigDecimal val,int scale){
		if(val == null){
			val = BigDecimal.ZERO;
		}
		
		return val.divide(D1, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	
	/**
     * 四舍五入
     * @param val
     * @param scale
     * @return
     */
    public static BigDecimal round(BigDecimal val,int scale){
        return val.divide(D1, scale, BigDecimal.ROUND_HALF_UP);
    }
}
